﻿@model  MvcPaging.PaginationModel
 @using MvcPaging

<div class="row">
    <div class="col-md-5 col-sm-12">
        <div class="paging_bootstrap">
            <ul class="pagination">
                @foreach (var link in Model.PaginationLinks)
                {
                    @BuildLink(link)
                }
            </ul>
        </div>
    </div>
</div>

@helper BuildLink(PaginationLink link)
{
    var liBuilder = new TagBuilder("li");
    if (link.IsCurrent)
    {
        liBuilder.MergeAttribute("class", "active");
    }
    if (!link.Active)
    {
        liBuilder.MergeAttribute("class", "disabled");
    }

    var aBuilder = new TagBuilder("a");
    if (link.Url == null)
    {
        aBuilder.MergeAttribute("href", "#");
    }
    else
    {
        aBuilder.MergeAttribute("href", link.Url);
    }

    // Ajax support
    if (Model.AjaxOptions != null)
    {
        foreach (var ajaxOption in Model.AjaxOptions.ToUnobtrusiveHtmlAttributes())
        {
            aBuilder.MergeAttribute(ajaxOption.Key, ajaxOption.Value.ToString(), true);
        }
    }

    aBuilder.SetInnerText(link.DisplayText);

    liBuilder.InnerHtml = aBuilder.ToString();

    @Html.Raw(liBuilder.ToString())
}
